This page is about trend in personal consumption in the US
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.4 v dplyr 1.0.7
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 2.0.1 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## 载入程辑包:'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(rvest)
##
## 载入程辑包:'rvest'
## The following object is masked from 'package:readr':
##
## guess_encoding
library(ggplot2)
library(lubridate)
##
## 载入程辑包:'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
Import data
consumption_product = readxl::read_excel("./data/consumption_product.xlsx") %>%
janitor::clean_names() %>%
pivot_longer(
x2019_q1 : x2021_q3,
names_to = "time",
names_prefix = "x",
values_to = "consumption"
)
## Warning in FUN(X[[i]], ...): strings not representable in native encoding will
## be translated to UTF-8
## Warning in FUN(X[[i]], ...): unable to translate '<U+00C4>' to native encoding
## Warning in FUN(X[[i]], ...): unable to translate '<U+00D6>' to native encoding
## Warning in FUN(X[[i]], ...): unable to translate '<U+00E4>' to native encoding
## Warning in FUN(X[[i]], ...): unable to translate '<U+00F6>' to native encoding
## Warning in FUN(X[[i]], ...): unable to translate '<U+00DF>' to native encoding
## Warning in FUN(X[[i]], ...): unable to translate '<U+00C6>' to native encoding
## Warning in FUN(X[[i]], ...): unable to translate '<U+00E6>' to native encoding
## Warning in FUN(X[[i]], ...): unable to translate '<U+00D8>' to native encoding
## Warning in FUN(X[[i]], ...): unable to translate '<U+00F8>' to native encoding
## Warning in FUN(X[[i]], ...): unable to translate '<U+00C5>' to native encoding
## Warning in FUN(X[[i]], ...): unable to translate '<U+00E5>' to native encoding
consumption_function = readxl::read_excel("./data/consumption_function.xlsx") %>%
janitor::clean_names() %>%
pivot_longer(
x2019_q1 : x2021_q3,
names_to = "time",
names_prefix = "x",
values_to = "consumption"
)
consumption_function_conclude = consumption_function %>%
filter(functions %in% c("Goods","Services","Household consumption expenditures7","Final consumption expenditures of nonprofit institutions serving households (NPISHs)1"))
consumption_function_conclude_fig = plot_ly(consumption_function_conclude)
changing tendency of personal consumption of different kinds of products
consumption_product %>%
plot_ly(x = ~time, y = ~consumption, type = "bar", yaxis="y", color = ~products)
## Warning: Ignoring 77 observations
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
changing tendency of personal consumption of different kinds of functions
consumption_function %>%
plot_ly(x = ~time, y = ~consumption, type = "bar", yaxis="y", color = ~functions)
## Warning: Ignoring 22 observations
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
consumption_function_conclude %>%
plot_ly(x = ~time, y = ~consumption, type = "scatter", mode = "lines", yaxis="y", color = ~functions)